<template>
    <van-cell class="comment">
        <div class="header">
            <van-image
                class="avatar"
                round
                width="36px"
                height="36px"
                :src="comment.aut_photo"
            />
            <div class="author-name">{{ comment.aut_name }}</div>
            <div class="like">
                {{ comment.like_count }}
                <van-icon
                    class="icon"
                    :name="'good-job' + (comment.is_liking ? '' : '-o')"
                    @click="$emit('onLike', comment)"
                />
            </div>
        </div>
        <div class="content">
            {{ comment.content }}
        </div>
        <div v-if="!isSub" class="footer">
            <van-button
                class="btn"
                round
                color="#ccc"
                size="mini"
                @click="$emit('onComment', comment)"
            >
                {{ comment.reply_count }} 回复
            </van-button>
            <div class="pub-date">
                {{ getRelativeTime(comment.pubdate) }}
            </div>
        </div>

    </van-cell>
</template>

<script>
import moment from 'moment';

export default {
    props: {
        comment: Object,
        isSub: {
            type: Boolean,
            default: false,
        },
    },
    methods: {
        // 获取相对时间
        getRelativeTime (time) {
            return moment(time).fromNow();
        },
    },
}
</script>
